<template>
  <div class="home-content">
    <!-- 头部区域 -->
    <div class="header-section">
      <img src="/images/主体页面组件/头部header.svg" alt="头部背景" class="header-bg" />
      <div class="header-content">
        <img src="/images/主体页面组件/头部蓝酒馆logo.svg" alt="蓝酒馆logo" class="header-logo" />
        <img src="/images/主体页面组件/头部slogan.svg" alt="slogan" class="header-slogan" />
      </div>
    </div>

    <!-- 主内容区域 -->
    <div class="main-content">
      <!-- 轮播图区域 -->
      <div class="carousel-section">
        <div class="carousel-container">
          <div class="carousel-slide" :class="{ active: currentSlide === 0 }">
            <img src="/images/主体页面组件/轮播图1.svg" alt="轮播图1" class="carousel-image" />
          </div>
          <div class="carousel-slide" :class="{ active: currentSlide === 1 }">
            <img src="/images/主体页面组件/轮播图2.svg" alt="轮播图2" class="carousel-image" />
          </div>
          <div class="carousel-slide" :class="{ active: currentSlide === 2 }">
            <img src="/images/主体页面组件/轮播图3.svg" alt="轮播图3" class="carousel-image" />
          </div>
        </div>
      </div>

      <!-- 店长推荐板块 -->
      <div class="recommendation-section">
        <img src="/images/主体页面组件/店长推荐板块bg.svg" alt="店长推荐内容" class="recommendation-bg" />
        <div class="recommendation-overlay">
          <img src="/images/主体页面组件/店长推荐板块标题.svg" alt="店长推荐" class="section-title-overlay" />
          <button class="more-btn-overlay">
            <img src="/images/主体页面组件/更多.svg" alt="更多" />
          </button>
        </div>
        <div class="books-container">
          <div class="book-item">
            <img src="/images/店长推荐/白夜行封面.svg" alt="白夜行封面" class="book-cover" />
            <img src="/images/店长推荐/白夜行书名.svg" alt="白夜行" class="book-title" />
          </div>
          <div class="book-item">
            <img src="/images/店长推荐/悲惨世界封面.svg" alt="悲惨世界封面" class="book-cover" />
            <img src="/images/店长推荐/悲惨世界书名.svg" alt="悲惨世界" class="book-title" />
          </div>
          <div class="book-item">
            <img src="/images/店长推荐/围城封面.svg" alt="围城封面" class="book-cover" />
            <img src="/images/店长推荐/围城书名.svg" alt="围城" class="book-title" />
          </div>
        </div>
      </div>

      <!-- 精选推荐板块 -->
      <div class="featured-section">
        <img src="/images/主体页面组件/精选推荐板块bg.svg" alt="精选推荐内容" class="featured-bg" />
        <div class="featured-overlay">
          <img src="/images/主体页面组件/精选推荐板块标题.svg" alt="精选推荐" class="section-title-overlay" />
          <button class="more-btn-overlay">
            <img src="/images/主体页面组件/更多.svg" alt="更多" />
          </button>
        </div>
        <div class="featured-books-container">
          <!-- 哲学的最后一课 -->
          <div class="featured-book-item" @click="$router.push('/book-detail')">
            <div class="book-info-left">
              <img src="/images/精选推荐/哲学的最后一课封面.svg" alt="哲学的最后一课封面" class="featured-book-cover" />
            </div>
            <div class="book-info-right">
              <img src="/images/精选推荐/哲学家的最后一课书名.svg" alt="哲学的最后一课" class="featured-book-title" />
              <img src="/images/精选推荐/哲学的最后一课推荐指数.svg" alt="推荐指数" class="featured-book-rating" />
              <img src="/images/精选推荐/哲学的最后一课作者.svg" alt="作者" class="featured-book-author" />
              <img src="/images/精选推荐/哲学的最后一课描述.svg" alt="描述" class="featured-book-desc" />
              <button class="collect-btn" @click.stop="toggleCollection('哲学的最后一课')">
                <img :src="bookCollections['哲学的最后一课'] ? '/images/主体页面组件/已收藏按钮.svg' : '/images/主体页面组件/收藏按钮.svg'" :alt="bookCollections['哲学的最后一课'] ? '已收藏' : '收藏'" />
              </button>
            </div>
          </div>

          <!-- 潮汐图 -->
          <div class="featured-book-item">
            <div class="book-info-left">
              <img src="/images/精选推荐/潮汐图封面.svg" alt="潮汐图封面" class="featured-book-cover" />
            </div>
            <div class="book-info-right">
              <img src="/images/精选推荐/潮汐图书名.svg" alt="潮汐图" class="featured-book-title" />
              <img src="/images/精选推荐/潮汐图推荐指数.svg" alt="推荐指数" class="featured-book-rating" />
              <img src="/images/精选推荐/潮汐图作者.svg" alt="作者" class="featured-book-author" />
              <img src="/images/精选推荐/潮汐图描述.svg" alt="描述" class="featured-book-desc" />
              <button class="collect-btn" @click="toggleCollection('潮汐图')">
                <img :src="bookCollections['潮汐图'] ? '/images/主体页面组件/已收藏按钮.svg' : '/images/主体页面组件/收藏按钮.svg'" :alt="bookCollections['潮汐图'] ? '已收藏' : '收藏'" />
              </button>
            </div>
          </div>

          <!-- 恐惧与自由 -->
          <div class="featured-book-item">
            <div class="book-info-left">
              <img src="/images/精选推荐/恐惧与自由封面.svg" alt="恐惧与自由封面" class="featured-book-cover" />
            </div>
            <div class="book-info-right">
              <img src="/images/精选推荐/恐惧与自由书名.svg" alt="恐惧与自由" class="featured-book-title" />
              <img src="/images/精选推荐/恐惧与自由推荐指数.svg" alt="推荐指数" class="featured-book-rating" />
              <img src="/images/精选推荐/恐惧与自由作者.svg" alt="作者" class="featured-book-author" />
              <img src="/images/精选推荐/恐惧与自由描述.svg" alt="描述" class="featured-book-desc" />
              <button class="collect-btn" @click="toggleCollection('恐惧与自由')">
                <img :src="bookCollections['恐惧与自由'] ? '/images/主体页面组件/已收藏按钮.svg' : '/images/主体页面组件/收藏按钮.svg'" :alt="bookCollections['恐惧与自由'] ? '已收藏' : '收藏'" />
              </button>
            </div>
          </div>

          <!-- 月亮与六便士 -->
          <div class="featured-book-item">
            <div class="book-info-left">
              <img src="/images/精选推荐/月亮与六便士封面.svg" alt="月亮与六便士封面" class="featured-book-cover" />
            </div>
            <div class="book-info-right">
              <img src="/images/精选推荐/月亮与六便士书名.svg" alt="月亮与六便士" class="featured-book-title" />
              <img src="/images/精选推荐/月亮与六便士推荐指数.svg" alt="推荐指数" class="featured-book-rating" />
              <img src="/images/精选推荐/月亮与六便士作者.svg" alt="作者" class="featured-book-author" />
              <img src="/images/精选推荐/月亮与六便士描述.svg" alt="描述" class="featured-book-desc" />
              <button class="collect-btn" @click="toggleCollection('月亮与六便士')">
                <img :src="bookCollections['月亮与六便士'] ? '/images/主体页面组件/已收藏按钮.svg' : '/images/主体页面组件/收藏按钮.svg'" :alt="bookCollections['月亮与六便士'] ? '已收藏' : '收藏'" />
              </button>
            </div>
          </div>

          <!-- 白夜行 -->
          <div class="featured-book-item">
            <div class="book-info-left">
              <img src="/images/精选推荐/白夜行封面.svg" alt="白夜行封面" class="featured-book-cover" />
            </div>
            <div class="book-info-right">
              <img src="/images/精选推荐/白夜行书名.svg" alt="白夜行" class="featured-book-title" />
              <img src="/images/精选推荐/白夜行推荐指数.svg" alt="推荐指数" class="featured-book-rating" />
              <img src="/images/精选推荐/白夜行作者.svg" alt="作者" class="featured-book-author" />
              <img src="/images/精选推荐/白夜行描述.svg" alt="描述" class="featured-book-desc" />
              <button class="collect-btn" @click="toggleCollection('白夜行')">
                <img :src="bookCollections['白夜行'] ? '/images/主体页面组件/已收藏按钮.svg' : '/images/主体页面组件/收藏按钮.svg'" :alt="bookCollections['白夜行'] ? '已收藏' : '收藏'" />
              </button>
            </div>
          </div>

          <!-- 悲惨世界 -->
          <div class="featured-book-item">
            <div class="book-info-left">
              <img src="/images/精选推荐/悲惨世界封面.svg" alt="悲惨世界封面" class="featured-book-cover" />
            </div>
            <div class="book-info-right">
              <img src="/images/精选推荐/悲惨世界书名.svg" alt="悲惨世界" class="featured-book-title" />
              <img src="/images/精选推荐/悲惨世界推荐指数.svg" alt="推荐指数" class="featured-book-rating" />
              <img src="/images/精选推荐/悲惨世界作者.svg" alt="作者" class="featured-book-author" />
              <img src="/images/精选推荐/悲惨世界描述.svg" alt="描述" class="featured-book-desc" />
              <button class="collect-btn" @click="toggleCollection('悲惨世界')">
                <img :src="bookCollections['悲惨世界'] ? '/images/主体页面组件/已收藏按钮.svg' : '/images/主体页面组件/收藏按钮.svg'" :alt="bookCollections['悲惨世界'] ? '已收藏' : '收藏'" />
              </button>
            </div>
          </div>

          <!-- 围城 -->
          <div class="featured-book-item">
            <div class="book-info-left">
              <img src="/images/精选推荐/围城封面.svg" alt="围城封面" class="featured-book-cover" />
            </div>
            <div class="book-info-right">
              <img src="/images/精选推荐/围城书名.svg" alt="围城" class="featured-book-title" />
              <img src="/images/精选推荐/围城推荐指数.svg" alt="推荐指数" class="featured-book-rating" />
              <img src="/images/精选推荐/围城作者.svg" alt="作者" class="featured-book-author" />
              <img src="/images/精选推荐/围城描述.svg" alt="描述" class="featured-book-desc" />
              <button class="collect-btn" @click="toggleCollection('围城')">
                <img :src="bookCollections['围城'] ? '/images/主体页面组件/已收藏按钮.svg' : '/images/主体页面组件/收藏按钮.svg'" :alt="bookCollections['围城'] ? '已收藏' : '收藏'" />
              </button>
            </div>
          </div>
        </div>
      </div>
    </div>

    <!-- 底部导航栏 -->
    <div class="bottom-nav">
      <img src="/images/主体页面组件/底部导航栏bg.svg" alt="导航背景" class="nav-bg" />
      <div class="nav-items">
        <button class="nav-item active">
          <img src="/images/主体页面组件/首页logo.svg" alt="首页" />
          <span class="nav-text">首页</span>
        </button>
        <button class="nav-item" @click="$router.push('/recommend')">
          <img src="/images/主体页面组件/推荐logo.svg" alt="推荐" />
          <span class="nav-text">推荐</span>
        </button>
        <button class="nav-item" @click="$router.push('/bookshelf')">
          <img src="/images/主体页面组件/书架logo.svg" alt="书架" />
          <span class="nav-text">书架</span>
        </button>
        <button class="nav-item" @click="$router.push('/my')">
          <img src="/images/主体页面组件/我的logo.svg" alt="我的" />
          <span class="nav-text">我的</span>
        </button>
      </div>
    </div>
  </div>
</template>

<script setup lang="ts">
import { ref, onMounted, onUnmounted } from 'vue'

// 轮播图逻辑
const currentSlide = ref(0)
const totalSlides = 3
let autoSlideTimer: number | null = null

// 收藏状态管理
const bookCollections = ref({
  '哲学的最后一课': false,
  '潮汐图': true,
  '恐惧与自由': true,
  '月亮与六便士': false,
  '白夜行': false,
  '悲惨世界': true,
  '围城': false
} as Record<string, boolean>)

// 切换收藏状态
const toggleCollection = (bookName: string) => {
  bookCollections.value[bookName] = !bookCollections.value[bookName]
}

// 切换到指定幻灯片
const goToSlide = (index: number) => {
  currentSlide.value = index
}

// 自动轮播
const startAutoSlide = () => {
  autoSlideTimer = setInterval(() => {
    currentSlide.value = (currentSlide.value + 1) % totalSlides
  }, 3000) // 每3秒切换一次
}

// 停止自动轮播
const stopAutoSlide = () => {
  if (autoSlideTimer) {
    clearInterval(autoSlideTimer)
    autoSlideTimer = null
  }
}

onMounted(() => {
  startAutoSlide()
})

onUnmounted(() => {
  stopAutoSlide()
})
</script>

<style scoped>
.home-content {
  display: flex;
  flex-direction: column;
  height: 100vh;
  width: 100%;
  background: #f5f5f5;
  position: absolute;
  top: 0;
  left: 0;
  margin: 0;
  padding: 0;
  overflow: hidden;
  /* 禁用文本选择和拖拽 */
  user-select: none;
  -webkit-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
}

/* 头部区域样式 */
.header-section {
  position: relative;
  width: 100%;
  height: 65px;
  flex-shrink: 0;
  margin: 0;
  padding: 0;
  border: none;
  outline: none;
  background: #A2F2F8;
}

.header-bg {
  width: 100%;
  height: 100%;
  object-fit: fill;
  display: block;
  margin: 0;
  padding: 0;
  border: none;
  outline: none;
}

.header-content {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  flex-direction: row;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
}

.header-logo {
  height: 30px;
  width: auto;
  transform: translateY(35%) translateX(10%);
}

.header-slogan {
  height: 40px;
  width: auto;
  transform: translateY(35%) translateX(50%);
}

/* 主内容区域样式 */
.main-content {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 15px;
  padding-bottom: 130px; /* 为导航栏留出空间 */
  display: flex;
  flex-direction: column;
  gap: 0;
  margin-top: 0;
  min-height: 0;
  /* 启用移动端原生滑动 */
  -webkit-overflow-scrolling: touch;
  scroll-behavior: smooth;
  /* 隐藏滚动条 */
  scrollbar-width: none;
  -ms-overflow-style: none;
}

/* 完全隐藏滚动条 */
.main-content::-webkit-scrollbar {
  display: none;
}

/* 板块通用样式 */
.recommendation-section,
.featured-section {
  position: relative;
  border-radius: 12px;
  overflow: hidden;
  margin-bottom: 25px;
}

/* 轮播图样式 */
.carousel-section {
  position: relative;
  margin-bottom: 30px;
  border-radius: 12px;
  overflow: hidden;
  flex-shrink: 0;
}

.carousel-container {
  position: relative;
  width: 100% !important;
  height: 250px !important;
  min-height: 250px !important;
  max-height: 250px !important;
  overflow: hidden;
  flex-shrink: 0;
}

.carousel-slide {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  opacity: 0;
  transition: opacity 0.5s ease-in-out;
}

.carousel-slide.active {
  opacity: 1;
}

.carousel-image {
  width: 95%;
  height: 95%;
  object-fit: contain;
  border-radius: 12px;
  margin: 2.5%;
}



/* 店长推荐板块特殊样式 */
.recommendation-section {
  transform: translateY(0);
  min-height: 200px;
  height: auto;
  margin-bottom: 10px;
  padding-bottom: 20px;
}

/* 书籍容器样式 */
.books-container {
  position: absolute;
  bottom: 15px;
  left: 15px;
  right: 15px;
  top: 50px;
  display: flex;
  flex-wrap: wrap;
  justify-content: space-around;
  align-content: flex-start;
  gap: 10px;
  overflow: hidden;
  padding: 5px;
  z-index: 10;
}

.book-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  flex: 0 1 calc(33.333% - 8px);
  min-width: 70px;
  max-width: 90px;
  cursor: pointer;
  transition: transform 0.2s ease;
  margin-bottom: 5px;
}

.book-item:hover {
  transform: translateY(-2px);
}

.book-cover {
  width: 60px;
  height: 75px;
  object-fit: contain;
  border-radius: 6px;
  margin-bottom: 5px;
  box-shadow: 0 3px 8px rgba(0, 0, 0, 0.15);
  background: transparent;
}

.book-title {
  width: auto;
  height: 16px;
  object-fit: contain;
  z-index: 15;
  position: relative;
}

/* 精选推荐板块特殊样式 */
.featured-section {
  margin-top: 5px;
  min-height: 800px;
  height: auto;
  position: relative;
}

.recommendation-bg,
.featured-bg {
  width: 100%;
  height: auto;
  border-radius: 12px;
  display: block;
  position: relative;
  z-index: 1;
}

/* 覆盖层样式 */
.recommendation-overlay {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  padding: 15px 20px;
  z-index: 5;
}

.featured-overlay {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 50px;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  padding: 15px 20px;
  z-index: 5;
}

.section-title-overlay {
  height: 25px;
  width: auto;
}

.more-btn-overlay {
  background: none;
  border: none;
  cursor: pointer;
  padding: 5px;
  transition: transform 0.2s ease;
}

.more-btn-overlay:hover {
  transform: scale(1.1);
}

.more-btn-overlay img {
  height: 20px;
  width: auto;
}

/* 精选推荐书籍容器 */
.featured-books-container {
  position: absolute;
  top: 50px;
  left: 0;
  right: 0;
  bottom: 0;
  margin-top: 15px;
  padding: 0 15px;
  z-index: 10;
  overflow-y: auto;
  /* 隐藏滚动条但保持滚动功能 */
  scrollbar-width: none;
  -ms-overflow-style: none;
  /* 启用移动端原生滑动 */
  -webkit-overflow-scrolling: touch;
}

/* 隐藏webkit滚动条 */
.featured-books-container::-webkit-scrollbar {
  display: none;
}

.featured-book-item {
  display: flex;
  background: transparent;
  border-radius: 0;
  margin-bottom: 10px;
  padding: 8px 0;
  box-shadow: none;
  align-items: flex-start;
  position: relative;
}

.book-info-left {
  flex-shrink: 0;
  margin-right: 10px;
}

.featured-book-cover {
  width: 72px;
  height: 90px;
  object-fit: contain;
  border-radius: 4px;
}

.book-info-right {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.featured-book-title {
  height: 16px;
  max-width: 100%;
  object-fit: contain;
  object-position: left;
}

.featured-book-author {
  height: 12px;
  max-width: 100%;
  object-fit: contain;
  object-position: left;
}

.featured-book-rating {
  height: 16px;
  max-width: 100%;
  object-fit: contain;
  object-position: left;
}

.featured-book-desc {
  height: auto;
  max-width: 100%;
  margin-bottom: 5px;
  font-size: 12px;
}

.featured-book-item .collect-btn {
  background: none;
  border: none;
  cursor: pointer;
  padding: 0;
  position: absolute;
  top: 8px;
  right: 0;
}

.featured-book-item .collect-btn img {
  width: 45px;
  height: 15px;
}

/* 底部导航栏样式 */
.bottom-nav {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 100px;
  z-index: 9999;
  margin: 0;
  padding: 0;
  background: transparent;
  padding-top: 5px;
}

.nav-bg {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.nav-items {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  justify-content: space-around;
  align-items: flex-start;
  padding: 0px 20px 20px 20px;
}

.nav-item {
  background: none;
  border: none;
  cursor: pointer;
  padding: 6px 8px 12px 8px;
  transition: transform 0.2s ease;
  border-radius: 8px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  gap: 4px;
}

.nav-item:hover {
  transform: scale(1.1);
}

.nav-item.active {
  background: rgba(0, 212, 255, 0.1);
}

.nav-item img {
  height: 32px;
  width: auto;
}

.nav-text {
  font-size: 12px;
  color: #ffffff;
  font-weight: 400;
  margin-top: 2px;
}

.nav-item.active .nav-text {
  color: #0033ff;
  font-weight: 500;
}



/* 响应式调整 */
@media (max-height: 700px) {
  .header-section {
    height: 100px;
  }
  
  .main-content {
    padding: 15px 12px;
    padding-bottom: 90px;
    gap: 20px;
  }
  
  .bottom-nav {
    bottom: 0;
    height: 100px;
    padding-top: 5px;
  }
  
  .nav-item img {
    height: 28px;
  }
  
  .nav-text {
    font-size: 11px;
  }
}

/* 大屏幕时优化显示 */
@media (min-width: 400px) {
  .books-container {
    justify-content: space-between;
    padding: 10px;
  }
  
  .book-item {
    flex: 0 1 calc(33.333% - 10px);
    max-width: 100px;
  }
  
  .book-cover {
    width: 70px;
    height: 90px;
  }
  
  .book-title {
    height: 18px;
  }
  
  .recommendation-section {
    min-height: 220px;
  }
}

/* 小屏幕时书籍纵向排列 */
@media (max-width: 399px) {
  .books-container {
    flex-direction: column;
    align-items: center;
    justify-content: flex-start;
    padding-top: 10px;
  }
  
  .book-item {
    flex: none;
    width: 100%;
    max-width: 120px;
    margin-bottom: 15px;
  }
  
  .recommendation-section {
    min-height: 280px;
  }
}

/* 高度不足时调整 */
@media (max-height: 600px) {
  .books-container {
    flex-direction: row;
    flex-wrap: wrap;
    justify-content: space-around;
  }
  
  .book-item {
    flex: 0 1 calc(50% - 10px);
    margin-bottom: 10px;
  }
  
  .book-cover {
    width: 55px;
    height: 70px;
  }
  
  .book-title {
    height: 16px;
  }
}

/* 精选推荐响应式样式 */
@media (max-width: 399px) {
  .featured-book-item {
    padding: 6px 0;
    margin-bottom: 8px;
  }
  
  .featured-book-cover {
    width: 66px;
    height: 82px;
  }
  
  .book-info-right {
    gap: 2px;
  }
  
  .featured-books-container {
    padding: 0 10px;
  }
  
  .featured-book-title {
    height: 14px;
  }
  
  .featured-book-author {
    height: 10px;
  }
  
  .featured-book-rating {
    height: 14px;
  }
}

@media (min-width: 400px) {
  .featured-book-cover {
    width: 78px;
    height: 96px;
  }
  
  .book-info-right {
    gap: 4px;
  }
}

@media (max-height: 700px) {
  .featured-book-item {
    padding: 5px 0;
    margin-bottom: 8px;
  }
  
  .featured-book-cover {
    width: 60px;
    height: 74px;
  }
  
  .book-info-right {
    gap: 2px;
  }
}
</style> 